home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Games / warp / score.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  18.2 KB  |  713 lines

  1. /* $Header: /b/iv/src/warp/RCS/score.c,v 1.1 1993/06/11 21:23:54 iv Exp iv $ */
  2.  
  3. /* $Log: score.c,v $
  4.  * Revision 1.1  1993/06/11  21:23:54  iv
  5.  * Initial revision
  6.  *
  7.  * Revision 7.0.1.2a  87/07/03  02:13:26  games
  8.  * Fixed numerous long vs. int bugs in printfs, etc.
  9.  * 
  10.  * Revision 7.0.1.2  86/10/20  12:06:56  lwall
  11.  * Made all exits reset tty.
  12.  * 
  13.  * Revision 7.0.1.1  86/10/16  10:52:47  lwall
  14.  * Added Damage.  Fixed random bugs.
  15.  * 
  16.  * Revision 7.0  86/10/08  15:13:14  lwall
  17.  * Split into separate files.  Added amoebas and pirates.
  18.  * 
  19.  */
  20.  
  21. #include "EXTERN.h"
  22. #include "warp.h"
  23. #include "intrp.h"
  24. #include "object.h"
  25. #include "play.h"
  26. #include "sig.h"
  27. #include "term.h"
  28. #include "us.h"
  29. #include "util.h"
  30. #include "weapon.h"
  31. #include "INTERN.h"
  32. #include "score.h"
  33.  
  34. void
  35. score_init()
  36. {
  37.     Reg1 char *s;
  38.     Reg2 int i;
  39.     FILE *savfil;
  40.  
  41.     if (stat(SAVEDIR,&filestat)) {
  42.     printf("Cannot access %s\r\n",SAVEDIR);
  43.     finalize(1);
  44.     }
  45.     if (filestat.st_uid != geteuid()) {
  46.     printf("Warp will not run right without being setuid.\r\n");
  47.     finalize(1);
  48.     }
  49.     if ((filestat.st_mode & 0605) != 0605) {
  50.     printf("%s is not protected correctly (must be u+rw o+rx).\r\n",SAVEDIR);
  51.     finalize(1);
  52.     }
  53.     
  54. #ifdef SCOREFULL
  55.     interp(longlognam, sizeof longlognam, "%N");
  56.     for (i=strlen(longlognam); i<24; i++)
  57.     longlognam[i] = ' ';    /* make sure it is 24 long for strncmp */
  58.     longlognam[24] = '\0';
  59. #else
  60.     interp(longlognam, sizeof longlognam, "%L");
  61.     for (i=strlen(longlognam); i<8; i++)
  62.     longlognam[i] = ' ';    /* make sure it is 8 long for strncmp */
  63.     longlognam[8] = '\0';
  64. #endif
  65.     
  66.     if (scorespec)
  67.     wscore();
  68.  
  69.     Sprintf(savefilename, "%s/save.%s", SAVEDIR, logname);
  70.  
  71.     savfil = experimenting ? NULL : fopen(savefilename,"r");
  72.     if (savfil != NULL && fgets(spbuf,100,savfil) != NULL) {
  73.     char tmpbuf[80];
  74.  
  75.     spbuf[strlen(spbuf)-1] = '\0';
  76.     if (fgets(tmpbuf,80,savfil) != NULL) {
  77.         int processnum;
  78.  
  79.         tmpbuf[strlen(tmpbuf)-1] = '\0';
  80.         printf("You seem to have left a game %s.\r\n",tmpbuf+9);
  81.         s = index(tmpbuf+9, ',');
  82.         *s = '\0';
  83.         processnum = atoi(s+11);
  84.         if (kill(processnum, SIGINT)) {
  85.                     /* does process not exist? */
  86.                     /* (warp ignores SIGINT) */
  87.         printf("\r\n\
  88. That process does not seem to exist anymore, so you'll have to start the\r\n");
  89.         printf(
  90. "last wave over.\r\n\n");
  91.         printf(
  92. "                      [type anything to continue]");
  93.         Fflush(stdout);
  94.         eat_typeahead();
  95.         getcmd(tmpbuf);
  96.         if (*tmpbuf == INTRCH)
  97.             finalize(0);
  98.         printf("\r\n");
  99.         }
  100.         else {
  101.         if (strcmp(term+8,tmpbuf+23)) {
  102.             printf(
  103. "That is not your current terminal--you are on %s.\r\n", term+5);
  104.             printf("\r\nYour options:\r\n");
  105.             printf("   1) Exit and find the terminal it's running on\r\n");
  106.         }
  107.         else {
  108.             printf("\r\nYour options:\r\n");
  109.             printf("   1) Exit and try to foreground it\r\n");
  110.         }
  111.         printf("   2) Let me terminate the other game\r\n\n");
  112.         printf("What do you want to do? ");
  113.         Fflush(stdout);
  114.         eat_typeahead();
  115.         getcmd(tmpbuf);
  116.         printf("\r\n");
  117.         if (*tmpbuf == INTRCH)
  118.             finalize(0);
  119.         if (*tmpbuf == '1') {
  120.             printf(
  121. "If you don't succeed, come back and do option 2 instead.  Good luck.\r\n");
  122.             finalize(0);
  123.         }
  124.         printf(
  125. "Ok, hang on a few moments \r\n");
  126.         Fclose(savfil);
  127.         if (kill(processnum, SIGQUIT)) {
  128.             printf("Unable to kill process #%d!\r\n",processnum);
  129.             roundsleep(2);
  130.         }
  131.         else {
  132. #ifdef SIGCONT
  133.             kill(processnum, SIGCONT);
  134. #endif
  135.             for (i=15; i; --i) {
  136.             sleep(1);
  137.             if (kill(processnum,SIGINT))
  138.                     /* does process not exist? */
  139.                     /* (warp ignores SIGINT) */
  140.                 break;
  141.             }
  142.             didkill++;
  143.         }
  144.         savfil = fopen(savefilename,"r");
  145.         if (savfil != NULL) {
  146.             Fgets(spbuf,100,savfil);
  147.         }
  148.         }
  149.     }
  150.     }
  151.     else
  152.     savfil = NULL;
  153.     if (savfil == NULL) {
  154.     totalscore = smarts = cumsmarts = wave = 0;
  155.     numents = 5;
  156.     numbases = 3;
  157.     }
  158.     else {
  159.     totalscore = atol(spbuf+9);
  160.     smarts = atoi(spbuf+20);
  161.     cumsmarts = atoi(spbuf+24);
  162.     numents = atoi(spbuf+30);
  163.     numbases = atoi(spbuf+33);
  164.     wave = atoi(spbuf+36);
  165.     apolspec = (spbuf[40] == 'a');
  166.     beginner   = (spbuf[41] == 'b');
  167.     crushspec  = (spbuf[42] == 'c');
  168.     gornspec   = (spbuf[43] == 'g');
  169.     massacre   = (spbuf[44] == 'm');
  170.     romspec    = (spbuf[45] == 'r');
  171.     tholspec   = (spbuf[46] == 't');
  172.     lowspeed   = (spbuf[47] == 'l') || lowspeed;
  173.     amoebaspec = (spbuf[48] == '&');
  174.     Fclose(savfil);
  175.     }
  176.  
  177.     if (!ismarts) {
  178.     ismarts = 1;
  179.     clear();
  180.     page(NEWSFILE,FALSE);
  181.     if (smarts) {
  182.         printf("\r\nSaved game: SCORE DIFF CUMDIFF ENTERPRISES BASES WAVE");
  183.         printf("\r\n          %7ld  %2d   %4d        %1d        %1d   %3d",
  184.         totalscore,smarts,cumsmarts,numents,numbases,wave);
  185.     }
  186.     printf("\r\nWould you like instructions? ");
  187.     Fflush(stdout);
  188.     eat_typeahead();
  189.     getcmd(buf);
  190.     printf("\r\n");
  191.     if (*buf == INTRCH)
  192.         finalize(0);
  193.     if (*buf == 'Y' || *buf == 'y') {
  194.         page(HELPFILE,FALSE);
  195.         printf("\r\nWould you like to play easy games for a while? ");
  196.         Fflush(stdout);
  197.         eat_typeahead();
  198.         getcmd(buf);
  199.         printf("\r\n");
  200.         if (*buf == 'Y' || *buf == 'y') {
  201.         beginner = TRUE;
  202.         lowspeed = TRUE;
  203.         }
  204.     }
  205.     }
  206.     if (!smarts)
  207.     smarts = ismarts;
  208. }
  209.  
  210. void
  211. wscore()
  212. {
  213.     clear();
  214.     printf("                             TOP WARPISTS\r\n\n");
  215.     printf("RANK  WHO                     AKA        SCORE DIFF  CUMDIFF  WHEN\r\n");
  216.     page(SCOREBOARD,TRUE);
  217.     printf("                     [Type anything to continue]");
  218.     Fflush(stdout);
  219.     getcmd(spbuf);
  220.     if (*spbuf == INTRCH)
  221.     finalize(0);
  222.     clear();
  223.     printf("                        TOP LOW-SPEED WARPISTS\r\n\n");
  224.     printf("RANK  WHO                     AKA        SCORE DIFF  CUMDIFF  WHEN\r\n");
  225.     page(LSCOREBOARD,TRUE);
  226.     printf("                     [Type anything to continue]");
  227.     Fflush(stdout);
  228.     getcmd(spbuf);
  229.     if (*spbuf == INTRCH)
  230.     finalize(0);
  231.     clear();
  232.     printf("                          TOP FUNNY WARPISTS\r\n\n");
  233.     printf("RANK  WHO                     AKA        SCORE DIFF  CUMDIFF  WHEN\r\n");
  234.     page(FSCOREBOARD,TRUE);
  235.     printf("                     [Type anything to continue]");
  236.     Fflush(stdout);
  237.     getcmd(spbuf);
  238.     if (*spbuf == INTRCH)
  239.     finalize(0);
  240.     clear();
  241.     printf("          GAMES SAVED OR IN PROGRESS\r\n\n");
  242.     printf("WHO           SCORE  DF   CDF  E  B  WV  FLAGS\r\n");
  243.     resetty();
  244.     Sprintf(spbuf,"/bin/cat %ssave.*",SAVEDIR);
  245. #ifndef lint
  246.     execl("/bin/sh", "sh", "-c", spbuf, 0);
  247. #endif
  248.     finalize(1);
  249. }
  250.  
  251.  
  252. void
  253. display_status()
  254. {
  255.     Reg1 int tmp;
  256.     static char *status_names[] = {"Impl", "Warp", "Base", "****" };
  257.  
  258.     if (oldstatus != status) {
  259.     Sprintf(spbuf,"%-4s",status_names[status]);
  260.     mvaddstr(0,0, spbuf);
  261.     oldstatus = status;
  262.     }
  263.     if (ent) {
  264.     if (ent->energy != oldeenergy) {
  265.         oldeenergy = ent->energy;
  266.         Sprintf(spbuf,"%4ld",oldeenergy);
  267.         mvaddstr(0,8, spbuf);
  268.     }
  269.     if (etorp != oldetorp) {
  270.         Sprintf(spbuf,"%2d",etorp);
  271.         mvaddstr(0,13, spbuf);
  272.         oldetorp = etorp;
  273.     }
  274.     }
  275.     else {
  276.     if (etorp >= 0) {
  277.         etorp = -1;
  278.         mvaddstr(0,8,"*******");
  279.         damage = 0;
  280.     }
  281.     }
  282.     if (base) {
  283.     if (base->energy != oldbenergy) {
  284.         oldbenergy = base->energy;
  285.         Sprintf(spbuf,"%5ld",oldbenergy);
  286.         mvaddstr(0,19, spbuf);
  287.     }
  288.     if (btorp != oldbtorp) {
  289.         Sprintf(spbuf,"%3d",btorp);
  290.         mvaddstr(0,25, spbuf);
  291.         oldbtorp = btorp;
  292.     }
  293.     }
  294.     else {
  295.     if (btorp >= 0) {
  296.         btorp = -1;
  297.         mvaddstr(0,19,"*********");
  298.     }
  299.     }
  300.     if (damage) {
  301.     if (!olddamage)
  302.         mvaddstr(0,42,"*** ");
  303.     if (damage > 1 || !damflag[dam]) {
  304.         do {
  305.         if (++dam == MAXDAMAGE)
  306.             dam = 0;
  307.         } while (!damflag[dam]);
  308.     }
  309.     if (!--damflag[dam]) {
  310.         olddamage = damage;
  311.         damage--;
  312.         Sprintf(spbuf,"%s OK ***       ",dammess[dam]);
  313.         spbuf[15] = '\0';
  314.         mvaddstr(0,46,spbuf);
  315.     }
  316.     else if (dam == NOSHIELDS) {
  317.         olddamage = damage;
  318.         tmp = (34 - damflag[dam]) * 3 - rand_mod(3);
  319.         if (tmp < 0)
  320.         tmp = 0;
  321.         Sprintf(spbuf,"%d%% %s ***       ",tmp,dammess[dam]);
  322.         spbuf[15] = '\0';
  323.         mvaddstr(0,46,spbuf);
  324.     }
  325.     else if (dam != lastdam || !olddamage) {
  326.         olddamage = damage;
  327.         Sprintf(spbuf,"NO %s ***       ",dammess[dam]);
  328.         spbuf[15] = '\0';
  329.         mvaddstr(0,46,spbuf);
  330.     }
  331.     if (status < 2) {
  332.         if (dam == NOIMPULSE && !entmode)
  333.         status = entmode = 1;
  334.         if (dam == NOWARP && entmode)
  335.         status = entmode = 0;
  336.     }
  337.     tmp = damflag[dam] * damage;
  338.     Sprintf(spbuf,"%3d.%1d ETR",tmp/10,tmp%10);
  339.     mvaddstr(0,69,spbuf);
  340.     lastdam = dam;
  341.     }
  342.     else {
  343.     if (olddamage) {
  344.         Sprintf(spbuf,"Stars: %-3d Stardate",numstars);
  345.         mvaddstr(0,42,spbuf);
  346.         lastdam = -1;
  347.         olddamage = 0;
  348.         oldcurscore = -1;
  349.     }
  350.     else if (numstars != oldstrs) {
  351.         Sprintf(spbuf,"%-3d",numstars);
  352.         mvaddstr(0,49, spbuf);
  353.     }
  354.     oldstrs = numstars;
  355.     }
  356.     if (numenemies != oldenemies) {
  357.     Sprintf(spbuf,"%-3d",numenemies);
  358.     mvaddstr(0,38, spbuf);
  359.     oldenemies = numenemies;
  360.     }
  361.     if (tmp = timer%10) {
  362.     Sprintf(spbuf,"%1d",tmp);
  363.     mvaddstr(0,67, spbuf);
  364.     }
  365.     else {
  366.     Sprintf(spbuf,"%5d.%1d",timer/10+smarts*100,tmp);
  367.     mvaddstr(0,61, spbuf);
  368.     }
  369.     if ((!damage || !damflag[dam]) && curscore != oldcurscore) {
  370.     Sprintf(spbuf,"%9ld",curscore);
  371.     mvaddstr(0,69, spbuf);
  372.     oldcurscore = curscore;
  373.     }
  374. }
  375.  
  376. void
  377. wavescore()
  378. {
  379.     double power, effectscore, starscore, pi_over_2;
  380.     long bonuses;
  381.     long tmp;
  382.     FILE *mapfp;
  383.     int row;
  384.     double pow();
  385. #ifndef lint
  386.     double atan2();
  387. #endif
  388.  
  389.     clear();
  390.     if (curscore > possiblescore)
  391.     curscore = possiblescore;
  392.     pi_over_2 = 3.14159265 / 2.0;
  393.     power = pow((double)inumenemies+     /* total number of enemies */
  394.             inumroms*2+      /* count roms 3 times */
  395.             inumgorns+       /* count gorns 2 times */
  396.             inumthols+       /* count thols 2 times */
  397.             inumapollos*4+   /* count apollo 5 times */
  398.             inumcrushes*3+   /* count crushers 4 times */
  399.             inumamoebas*5     /* count amoebas 6 times */
  400.         , 0.50) *                    /* skew it a little */
  401.         (double)smarts;              /* average energy and intelligence */
  402.     if (inumstars < 350 && inumenemies > 5)
  403.         power += (350.0 - (double)inumstars) * ((double)inumenemies - 5.0);
  404.     if (inumstars > 850 && inumenemies > 2)
  405.         power += ((double)inumstars - 850.0) * ((double)inumenemies - 2.0);
  406. #ifndef lint
  407.     effectscore = ((double)curscore / possiblescore) *
  408.     atan2(power, (double) timer + 1.0) / pi_over_2;
  409. #else
  410.     effectscore = pi_over_2;
  411. #endif
  412.     if (inumstars)
  413.     starscore = (double) numstars / (double) inumstars;
  414.     else
  415.     starscore = 1.0;
  416.     wave++;
  417.     Sprintf(spbuf,"Wave = %d, Difficulty = %d, cumulative difficulty = %d",
  418.      wave, smarts, cumsmarts);
  419.     mvaddstr(1, 13+(smarts<10), spbuf);
  420.     mvaddstr( 4, 68, " BONUS");
  421.     Sprintf(spbuf,"Efficiency rating:       %1.8f (diff=%0.2f,time=%d)",
  422.      effectscore, power, timer + 1);
  423.     mvaddstr( 5,5, spbuf);
  424.     if (effectscore < 0.8)
  425.     bonuses = tmp = 0;
  426.     else
  427.     bonuses = tmp = (long) ((effectscore-0.8) * smarts * 1000);
  428.     Sprintf(spbuf, "%6ld", tmp);
  429.     mvaddstr( 5, 68, spbuf);
  430.     Sprintf(spbuf,"Star save ratio:         %1.8f (%d/%d)",
  431.     starscore, numstars, inumstars);
  432.     mvaddstr( 6,5, spbuf);
  433. #ifndef lint
  434.     bonuses += tmp = (long) (((double)curscore / possiblescore) *
  435.     (starscore*starscore) * smarts * 20);
  436. #endif
  437.     Sprintf(spbuf, "%6ld", tmp);
  438.     mvaddstr( 6, 68, spbuf);
  439.     row = 7;
  440.     if (inuminhab != numinhab) {
  441.     Sprintf(spbuf, "Inhabited stars depopulated:  %5d", inuminhab-numinhab);
  442.     mvaddstr(row,5, spbuf);
  443.     bonuses += tmp = (long) (inuminhab-numinhab) * -500;
  444.     Sprintf(spbuf, "%6ld", tmp);
  445.     mvaddstr(row, 68, spbuf);
  446.     row++;
  447.     }
  448.     if (inumfriends != numfriends) {
  449.     Sprintf(spbuf, "Friendly craft destroyed:     %5d",
  450.         inumfriends-numfriends);
  451.     mvaddstr(row,5, spbuf);
  452.     bonuses += tmp = (long) (inumfriends-numfriends) * -250;
  453.     Sprintf(spbuf, "%6ld", tmp);
  454.     mvaddstr(row, 68, spbuf);
  455.     row++;
  456.     }
  457.     if (deadmudds) {
  458.     mvaddstr(row,5,"For destroying Harry Mudd:");
  459.     bonuses += tmp = (long) rand_mod(deadmudds * 20 + 1) - deadmudds*10;
  460.     Sprintf(spbuf, "%6ld", tmp);
  461.     mvaddstr(row, 68, spbuf);
  462.     row++;
  463.     }
  464.     if (bombed_out) {
  465.     mvaddstr(row,5, "For running away from reality:");
  466.     bonuses += tmp = (long) -possiblescore/2;
  467.     Sprintf(spbuf, "%6ld", tmp);
  468.     mvaddstr(row, 68,  spbuf);
  469.     row++;
  470.     }
  471.     if (row < 9)
  472.     row++;
  473.     Sprintf(spbuf, "Enterprise: %-9s%5d remaining",
  474.     !ient?"":ent?"saved":"destroyed", numents);
  475.     mvaddstr(row,5, spbuf);
  476.     bonuses += tmp = ent && !bombed_out ? (smarts+1)*15 : 0;
  477.     Sprintf(spbuf, "%6ld", tmp);
  478.     mvaddstr(row, 68, spbuf);
  479.     row++;
  480.     Sprintf(spbuf, "Base: %-9s      %5d remaining",
  481.     !ibase?"":base?"saved":"destroyed", numbases);
  482.     mvaddstr(row,5, spbuf);
  483.     bonuses += tmp = base && !bombed_out ? (smarts+1)*10 : 0;
  484.     Sprintf(spbuf, "%6ld", tmp);
  485.     mvaddstr(row, 68,  spbuf);
  486.     if (beginner) {
  487.     mvaddstr(13+(row>11),19, "(Special games count only a tenth as much)");
  488.     curscore /= 10;
  489.     bonuses /= 10;
  490.     }
  491.     Sprintf(spbuf, "Previous point total:%10ld",lastscore);
  492.     mvaddstr(15,24, spbuf);
  493.     Sprintf(spbuf, "Points this round:   %10ld",curscore);
  494.     mvaddstr(16,24, spbuf);
  495.     Sprintf(spbuf, "Bonuses:             %10ld",bonuses);
  496.     mvaddstr(17,24, spbuf);
  497.     totalscore = lastscore + curscore + bonuses;
  498.     Sprintf(spbuf, "New point total:     %10ld",totalscore);
  499.     mvaddstr(18,24, spbuf);
  500.     if (lastscore / ENTBOUNDARY < totalscore / ENTBOUNDARY) {
  501.     mvaddstr(row-1,42,"+ 1 new");
  502.     numents++;
  503.     }
  504.     else if (numents>0 &&
  505.     lastscore / ENTBOUNDARY > totalscore / ENTBOUNDARY) {
  506.     mvaddstr(row-1,42,"- 1 obsolete");
  507.     numents--;
  508.     }
  509.     if (lastscore / BASEBOUNDARY < totalscore / BASEBOUNDARY) {
  510.     mvaddstr(row,42,"+ 1 new");
  511.     numbases++;
  512.     }
  513.     else if (numbases>0 &&
  514.     lastscore / BASEBOUNDARY > totalscore / BASEBOUNDARY) {
  515.     mvaddstr(row,42,"- 1 obsolete");
  516.     numbases--;
  517.     }
  518.     if (starscore < 0.8 && inumstars > 200 && numstars > 50) {
  519.     Sprintf(spbuf, "smap.%d",rand_mod(MAPS-PERMMAPS)+PERMMAPS);
  520.     if ((mapfp = fopen(spbuf,"w")) != NULL) {
  521.         Reg1 OBJECT *obj;
  522.  
  523.         fprintf(mapfp,"%d\n",numstars);
  524.         for (obj = root.next; obj != &root; obj = obj->next) {
  525.         if (obj->type == Star) {
  526.             fprintf(mapfp,"%d %d\n",obj->posy,obj->posx);
  527.         }
  528.         }
  529.         Fclose(mapfp);
  530.     }
  531.     }
  532. }
  533.  
  534. void
  535. score()
  536. {
  537.     char tmp, *retval, cdate[30];
  538.     Reg1 FILE *logfd;
  539.     Reg2 FILE *outfd;
  540.     Reg3 int i;
  541.     long nowtime, time();
  542.     char *scoreboard;
  543.  
  544.     for (i=0; link(LOGFILE, LOCKFILE) == -1 && i<10; i++)
  545.     sleep(1);
  546.     nowtime = time((long *)0);
  547.     strcpy(cdate,ctime(&nowtime));
  548.     if ((logfd = fopen(LOGFILE,"a")) != NULL) {
  549.     fprintf(logfd,
  550.         "%-24s%-9s%7ld%c%2d %4d %s",
  551.         realname, logname, totalscore, c,smarts, cumsmarts, cdate);
  552.     Fclose(logfd);
  553.     }
  554.     strcpy(cdate+11,cdate+20);
  555.     if (beginner)
  556.     scoreboard = FSCOREBOARD;
  557.     else if (lowspeed)
  558.     scoreboard = LSCOREBOARD;
  559.     else
  560.     scoreboard = SCOREBOARD;
  561.     if (eaccess(scoreboard,0)) {
  562.     if ((logfd = fopen(scoreboard,"w")) != NULL)
  563.         Fclose(logfd);
  564.     }
  565.     if ((logfd = fopen(scoreboard,"r")) != NULL &&
  566.     (outfd = fopen(TMPSCOREBOARD,"w")) != NULL) {
  567.     for (i=0; i<20; i++) {
  568.         if ((retval = fgets(buf, 100, logfd)) == NULL)
  569.         break;
  570.         if (atol(buf+32) < totalscore)
  571.         break;
  572.         if (strnEQ(buf+COMPOFF,COMPNAME,COMPLEN)) {
  573.         i = 100;
  574.         break;
  575.         }
  576.         fprintf(outfd, "%s", buf);
  577.     }
  578.     if (i == 100) {
  579.         mvaddstr(20,21, "You did not better your previous score");
  580.         Fclose(outfd);
  581.         unlink(TMPSCOREBOARD);
  582.     }
  583.     else if (i < 20) {
  584.         fprintf(outfd, "%-24s%-8s%8ld%c %2d    %4d    %s",
  585.         realname, logname, totalscore, c,smarts, cumsmarts, cdate);
  586.         i++;
  587.         Sprintf(spbuf, "    Congratulations--you've placed %d%s",
  588.           i, i==1?"st":(i==2?"nd":(i==3?"rd":"th")));
  589.         if (retval != NULL) {
  590.         if (strnNE(buf+COMPOFF,COMPNAME,COMPLEN)) {
  591.             fprintf(outfd, "%s", buf);
  592.             i++;
  593.         }
  594.         else
  595.             strcpy(spbuf,"Congratulations--you've bettered your score");
  596.         while (i<20) {
  597.             if (fgets(buf, 100, logfd) == NULL)
  598.             break;
  599.             if (strnNE(buf+COMPOFF,COMPNAME,COMPLEN)) {
  600.             fprintf(outfd, "%s", buf);
  601.             i++;
  602.             }
  603.         }
  604.         }
  605.         mvaddstr(20,19, spbuf);
  606.         Fclose(logfd);
  607.         Fclose(outfd);
  608.         while (unlink(scoreboard) == 0)
  609.         ;
  610.         link(TMPSCOREBOARD,scoreboard);
  611.         unlink(TMPSCOREBOARD);
  612.         logfd = fopen(scoreboard,"r");
  613.     }
  614.     else {
  615.         mvaddstr(20,22,"You did not place within the top 20");
  616.         Fclose(outfd);
  617.     }
  618.     }
  619.     else {
  620.     Sprintf(spbuf,"(Cannot access %s file, error %d)",
  621.         (logfd==NULL?"log":"tmp"),errno);
  622.     mvaddstr(20,22,spbuf);
  623.     }
  624.     move(23,0,0);
  625.     erase_eol();
  626.     mvaddstr(23,11,
  627.     "[Hit space for scoreboard, 'r' for new game, 'q' to quit]");
  628.     unlink(LOCKFILE);
  629.     Fflush(stdout);
  630.     eat_typeahead();
  631.     do {
  632.     getcmd(&tmp);
  633.     } while (tmp != INTRCH && tmp != BREAKCH && !index(" rqQ",tmp));
  634.     if (index("qQr",tmp)) {
  635.     justonemoretime = (tmp == 'r');
  636.     if (logfd != NULL)
  637.         Fclose(logfd);
  638.     }
  639.     else {
  640.     clear();
  641.     if (logfd != NULL) {
  642.         fseek(logfd, 0L, 0);
  643.         if (beginner)
  644.         mvaddstr(0,31,"TOP FUNNY WARPISTS");
  645.         else if (lowspeed)
  646.         mvaddstr(0,29,"TOP LOW-SPEED WARPISTS");
  647.         else
  648.         mvaddstr(0,33,"TOP WARPISTS");
  649.         mvaddstr(2,0,"RANK  WHO                     AKA        SCORE DIFF  CUMDIFF  WHEN");
  650.         for (i=1; i<=20; i++) {
  651.         if (fgets(buf, 100, logfd) == NULL)
  652.             break;
  653.         buf[strlen(buf)-1] = '\0';
  654.         Sprintf(spbuf, " %2d   %s", i, buf);
  655.         mvaddstr(i+2,0, spbuf);
  656.         }
  657.         Fclose(logfd);
  658.     }
  659.     roundsleep(1);
  660.     mvaddstr(23,25,"Would you like to play again?");
  661.     eat_typeahead();
  662.     do {
  663.         getcmd(&tmp);
  664.     } while (tmp != INTRCH && tmp != BREAKCH && !index("nNyY \n\r",tmp));
  665.     if (tmp == 'n' || tmp == 'N' || tmp == INTRCH || tmp == BREAKCH)
  666.         justonemoretime = FALSE;
  667.     }
  668.  
  669.     smarts = ismarts;
  670.     totalscore = cumsmarts = wave = 0;
  671.     numents = 5;
  672.     numbases = 3;
  673.     apolspec = FALSE;
  674.     beginner   = FALSE;
  675.     crushspec  = FALSE;
  676.     gornspec   = FALSE;
  677.     massacre   = (ismarts >= 40);
  678.     romspec    = FALSE;
  679.     tholspec   = FALSE;
  680. }
  681.  
  682. void
  683. save_game()
  684. {
  685.     FILE *savfil;
  686.  
  687.     if (experimenting)
  688.     return;
  689.     if ((savfil = fopen(savefilename,"w")) == NULL) {
  690.     resetty();
  691.     printf("Cannot save game\r\n");
  692.     finalize(1);
  693.     }
  694.     fprintf(savfil, "%-8s %10ld, %2d,%5d,%2d,%2d,%3d %c%c%c%c%c%c%c%c\n",
  695.     logname, totalscore, smarts, cumsmarts, numents, numbases, wave,
  696.     apolspec ? 'a' : ' ',
  697.     beginner   ? 'b' : ' ',
  698.     crushspec  ? 'c' : ' ',
  699.     gornspec   ? 'g' : ' ',
  700.     massacre   ? 'm' : ' ',
  701.     romspec    ? 'r' : ' ',
  702.     tholspec   ? 't' : ' ',
  703.     lowspeed   ? 'l' : ' ',
  704.     amoebaspec ? '&' : ' '
  705.     );
  706.     Fclose(savfil);
  707.     resetty();
  708.     if (panic)
  709.     finalize(0);
  710.     clear();
  711.     finalize(0);
  712. }
  713.